package zuosheng.weiyunsuan;

/**
 * @author lj
 * @Description: 不做任何比较判断找出两个数中最大数
 * @date 2020-11-16 14:59
 * @QQ 851477108
 */


public class MaxNumber {
    public static void main(String[] args) {
        int a = 2313,b =1239;
        System.out.println(Math.max(a,b));
        System.out.println(getMax(a,b));
    }

    public static int getMax(int a, int b){
        int c = a - b;
        int sa = sign(a);
        int sb = sign(b);
        int sc = sign(c);

        int difSab = sa ^ sb;
        int sameSab = flip(difSab);
        int returnA = difSab * sa + sameSab * sc;
        int returnB = flip(returnA);
        return a * returnA + b * returnB;
    }

    //返回整数n的符号,n正数返回1,负数返回0
    public static int sign(int n){
        return flip((n >> 31) & 1);
    }

    //n=0，返回1；n=1，返回0
    public static int flip(int n){
        return n ^ 1;
    }
}
